import java.io.*;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.BaseTree;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.stringtemplate.*;
import org.antlr.stringtemplate.language.*;


public class Main {
    // override nextToken to set startPos (this seems too hard)
    public static class MyLexer extends PythonLexer {
	public MyLexer(CharStream lexer) {
	    super(lexer);
	}
	public Token nextToken() {
	    startPos = getCharPositionInLine();
	    return super.nextToken();
	}
    }

    public static String _getLongText(BaseTree bt) {
        String longT = "";
        if(bt.getChildCount() == 0) {
            return bt.getText() + "  (type=" + bt.getType() + ") ";
        } else {
        	longT += "\n * " + bt.getText() + "  (type=" + bt.getType() + ") ";
            for (int i = 0; i < bt.getChildCount(); i++) {
                BaseTree childTree = (BaseTree)bt.getChild(i);
                longT += "\n " + _getLongText(childTree);
            }
        }
        return longT;
    }

    
    public static void main(String[] args) throws Exception {
		CharStream input = new ANTLRFileStream(args[0]);
		PythonLexer lexer = new MyLexer(input);
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		//tokens.discardOffChannelTokens(true);
		PythonTokenSource indentedSource = new PythonTokenSource(tokens);
		tokens = new CommonTokenStream(indentedSource);
		//System.out.println("tokens="+tokens.getTokens());
		PythonParser parser = new PythonParser(tokens);
		//parser.file_input();
		PythonParser.file_input_return returnResult = parser.file_input();
		CommonTree treeRoot = (CommonTree) returnResult.getTree();
		//for (int i = 0; i < treeRoot.getChildCount(); i++) {
		//	System.out.println(treeRoot.getChild(i).getType());
		//}
		//System.out.println(treeRoot.toStringTree());
		System.out.print(Main._getLongText(treeRoot));
		//PythonASTReader reader = new PythonASTReader(treeRoot);
		//reader.printFunctions();
    }
}
